home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 11 - 1995 / 11.02 Feb 95 / Yenta / Periodic Tasksƒ / CPPScanZones.cp < prev    next >
Encoding:
Text File  |  1996-04-04  |  3.4 KB  |  129 lines  |  [TEXT/KAHL]

  1. /********************************************************* DEFINITION
  2.     DATE:    9/17/93
  3.     AUTHOR: Eric R. Rosé
  4.     
  5.     CLASS:  CPPScanZones
  6.     
  7.     SUPERCLASS: CPPPeriodicTask
  8.     
  9.         This c++ class goes through our list of zones, checking each
  10.         for new Yenta nodes
  11.     
  12. ********************************************************************/
  13.  
  14. #include "CPPScanZones.h"
  15. #include <CPPTaskManager.h>
  16. #include <CPPStringList.h>
  17. #include "CPPZoneList.h"
  18. #include <CPPNode411.h>
  19. #include <StringTools.h>
  20.  
  21. extern    void    ProcessNodeLookupResults    (CPPObject *TheTask);
  22. extern    CPPZoneList        *gZoneList;    // pointer to the send dialog's zone list
  23. extern    void    SetStatusMessage (StringPtr NewMessage, Boolean MakeCopy);
  24.  
  25. extern    StringPtr        gAppName;
  26.  
  27. /*-----------------------------------------------------------------*/
  28. /*------------------------ PUBLIC METHODS -------------------------*/
  29. /*-----------------------------------------------------------------*/
  30.  
  31.     CPPScanZones::CPPScanZones (CPPTaskManager *TaskManager, 
  32.                                 long minPeriod, 
  33.                                 Boolean deleteWhenDone) :
  34.                               CPPPeriodicTask (TaskManager, minPeriod,
  35.                                                deleteWhenDone)
  36.     {
  37.         this->zoneList = NULL;
  38.         this->lookupTask = NULL;
  39.         this->whichZone = 0;
  40.     }
  41.     
  42. /*-----------------------------------------------------------------*/
  43.  
  44.     CPPScanZones::~CPPScanZones (void)
  45.     {
  46.         if (this->lookupTask)
  47.           delete this->lookupTask;
  48.         if (this->zoneList)
  49.           {
  50.               zoneList->DeleteItems(TRUE);
  51.             delete this->zoneList;
  52.           }
  53.     }
  54.     
  55. /*-----------------------------------------------------------------*/
  56.  
  57.     char *CPPScanZones::ClassName (void)
  58.     {
  59.         return "CPPScanZones";
  60.     }
  61.  
  62. /*-----------------------------------------------------------------*/
  63.  
  64.     void    CPPScanZones::DoPeriodicAction (void)
  65.     /* if the lookup has completed, advance to the next zone and */
  66.     /* start another lookup */
  67.     {
  68.         StringPtr    ZoneName;
  69.         Str32    TypeStr;
  70.         Str255        STemp;
  71.         
  72.         // call the inherited method to update frequency count
  73.         CPPPeriodicTask::DoPeriodicAction();
  74.  
  75.         if (lookupTask->hasCompleted)
  76.           {
  77.               this->whichZone++;
  78.               if (this->whichZone <= this->zoneList->GetNumItems())
  79.                 {
  80.                   ZoneName = (*zoneList)[this->whichZone];
  81.                 PStrCat (32, TypeStr, 2, "\p≈•", gAppName);
  82.                 lookupTask->StartNodeLookup("\p=", TypeStr, ZoneName, 50,
  83.                                             ProcessNodeLookupResults);
  84.                 PStrCat (255, STemp, 3, "\pScanning zone '", ZoneName, "\p' for new users.");
  85.                     SetStatusMessage (STemp, TRUE);
  86.                 }
  87.               else
  88.                 {
  89.                     this->hasCompleted = TRUE;
  90.                     this->callResult = noErr;
  91.                 }
  92.           }
  93.     }
  94.  
  95. /*-----------------------------------------------------------------*/
  96.  
  97.     void    CPPScanZones::DoCompletedAction (void)
  98.     {
  99.         CPPPeriodicTask::DoCompletedAction();
  100.     }
  101.     
  102. /*-----------------------------------------------------------------*/
  103.  
  104.     void CPPScanZones::StartScanZones (CompletionProc DoProc)
  105.     {
  106.         if (!this->hasCompleted)
  107.           return;
  108.           
  109.         // get rid of the old lookup and zone data (if any)
  110.         if (lookupTask)
  111.           delete this->lookupTask;
  112.         if (zoneList)
  113.           delete this->zoneList;
  114.           
  115.         // get a list of all the zones
  116.         this->zoneList = gZoneList->MakeListOfZones();
  117.     
  118.         // set up the lookup task
  119.         this->lookupTask = new CPPNode411 (this->ourManager, 30, FALSE);
  120.     
  121.         // note that we haven't completed yet
  122.         SetCompletionProc(DoProc);
  123.         this->hasCompleted = FALSE;
  124.         this->whichZone = 0;
  125.         
  126.         // add ourselves to the periodic task queue
  127.         this->ourManager->AddPeriodicTask(this);
  128.     }
  129.